package com.ytjj.qmyx.data.amqp.consumer;

import com.alibaba.fastjson.JSONObject;
import com.rabbitmq.client.Channel;
import com.ytjj.common.constants.QueueConstants;
import com.ytjj.common.dto.mqdto.AppDataStatisticsActivationDto;
import com.ytjj.common.dto.mqdto.OrderExpressDto;
import com.ytjj.common.dto.mqdto.OrderRecordDto;
import com.ytjj.qmyx.data.service.OrdersService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.support.AmqpHeaders;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Slf4j
@Component
public class OrderExpressListener {
    @Resource
    private OrdersService ordersService;

    @RabbitListener(queuesToDeclare = @Queue(value = QueueConstants.QUERY_SYNC_ORDER_EXPRESS, durable = "true"))
    public void syncOrderExpress(String orderExpressDtoStr, @Header(AmqpHeaders.DELIVERY_TAG) long deliveryTag, Channel channel) {
        log.info("收到一条消息syncOrderExpress消息{}:", orderExpressDtoStr);
        OrderExpressDto dto = JSONObject.parseObject(orderExpressDtoStr, OrderExpressDto.class);

        ordersService.syncOrderExpress(dto);
    }

}
